package com.zj.web.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

@Data
@AllArgsConstructor
public class MyUserDTO implements Serializable {
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;  //用户id

    @NotBlank(message = "用户名不为空")
    @Size(min = 3, max = 50, message = "用户名长度必须在3-50之间")
    private String userName;  //用户名
    @NotBlank(message = "密码不为空")
    @Size(min = 6, max = 100, message = "密码长度必须在6-100之间")
    private String userPassword;  //密码
    private Integer gender;//性别
    private String phone;  //电话
    private String email;  //邮箱
    private String headUrl;//头像url

    private Integer userStatus;//状态
    private Set<String> roles;//用户角色
    private Date optime;

    @JsonIgnore
    private MultipartFile avatarFile;
    @JsonIgnore
    private String token;
    @JsonIgnore
    private String verifyCode;


    public MyUserDTO(){}

    //用于快速注册
    public MyUserDTO(String userName, String userPassword){
        this.userName=userName;
        this.userPassword=userPassword;
    }
    //用于快速注册，带角色
    public MyUserDTO(String userName, String userPassword, Set<String> roles){
        this.userName=userName;
        this.userPassword=userPassword;
        this.roles=roles;
    }
    //用于快速注册，带所有参数
    public MyUserDTO(Long userId, String userName, String userPassword,
                     String mobile, String email, String avatar,
                     Integer gender, Integer userStatus, Set<String> roles){
        this.userId=userId;
        this.userName=userName;
        this.userPassword=userPassword;
        this.phone=mobile;
        this.email=email;
        this.headUrl=avatar;
        this.gender=gender;
        this.userStatus=userStatus;
        this.roles=roles;
    }

    //用于更新和查新
    public MyUserDTO(Long userId, String userName, Set<String> roles){
        this.userId=userId;
        this.userName=userName;
        this.roles=roles;
    }
    
    //用于根据 userId 更新全部数据
    public MyUserDTO(Long userId, String userName,
                      String mobile, String email, MultipartFile avatarFile,
                     Integer gender){
        this.userId=userId;
        this.userName=userName;
        this.phone=mobile;
        this.email=email;
        this.avatarFile=avatarFile;
        this.gender=gender;
    }

    //用于用户注册，带验证码
//    public MyUserDTO(String userName, String verifyCode){
//        this.userName=userName;
//        this.verifyCode=verifyCode;
//    }

}
